lazy-transform-str 0.0.1

Lazy-copying lazy-allocated scanning `str` transformations. This is good e.g. for (un)escaping text, especially if individual strings are short.
Documentation

Lazy-copying lazy-allocated scanning [str] transformations.
This is good e.g. for (un)escaping text, especially if individual strings are short.

Note that this library uses [smartstring] (and as such returns [Woc]s instead of [Cow]s).
The output is still [Deref<Target = str>] regardless, so there should be no issue with ease of use.

Example

use {
cervine::Cow,
gnaw::Unshift as _,
lazy_transform_str::{Transform as _, TransformedPart},
smartstring::alias::String,
};

fn double_a(str: &str) -> Cow<String, str> {
str.transform(|rest /*: &mut &str */| {
// Consume some of the input. `rest` is never empty here.
match rest.unshift().unwrap() {
'a' => TransformedPart::Changed(String::from("aa")),
_ => TransformedPart::Unchanged,
}
} /*: impl FnMut(…) -> … */ )
}

assert_eq!(double_a("abc"), Cow::Owned(String::from("aabc")));
assert_eq!(double_a("bcd"), Cow::Borrowed("bcd"));

See [escape_double_quotes] and [unescape_backlashed_verbatim]'s sources for more real-world examples.